package 数据结构和算法入门计划8月开始;
// https://leetcode-cn.com/problems/reverse-string-ii/
public class 反转字符串II5410820 {
    class Solution {
        public String reverseStr(String s, int k) {
            char[] cs = s.toCharArray();
            int n = s.length();
            for (int l = 0; l < n; l = l + 2 * k) {
                int r = l + k - 1;
                reverse(cs, l, Math.min(r, n - 1));
            }
            return String.valueOf(cs);
        }
        void reverse(char[] cs, int l, int r) {
            while (l < r) {
                char c = cs[l];
                cs[l] = cs[r];
                cs[r] = c;
                l++; r--;
            }
        }
    }


// https://leetcode-cn.com/problems/reverse-string-ii/solution/gong-shui-san-xie-jian-dan-zi-fu-chuan-m-p88f/

}
